package com.example.nna.voz;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.Spinner;

import com.example.nna.main.R;
import com.example.nna.util.UserInfo;

public class mainclass extends Activity{
	public UserInfo mUser;
	public Context mContext; 
    public Activity mActivity;
    public static int mNotifTimer;
    public static int mNotifTimerSelection;
    public static boolean mNotifEnable;
    public MylistView myadapter;
	@Override
	public boolean onMenuOpened(int featureId, Menu menu) {
		// TODO Auto-generated method stub
//		menu.findItem(R.id.menu_subscribe).setVisible(false);
//    	if(mUser.isLogin()){
//    		menu.findItem(R.id.menu_favourite).setVisible(true);
//    	}else{
//    		menu.findItem(R.id.menu_favourite).setVisible(false);
//    	}
		return super.onMenuOpened(featureId, menu);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		getMenuInflater().inflate(R.menu.activity_parser_html, menu);
		return super.onCreateOptionsMenu(menu);
	}

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.menu_settings:
	        LayoutInflater factory2 = LayoutInflater.from(mContext);
		    View textEntryView2 = factory2.inflate(R.layout.alertsetting, null); 
		    CheckBox checkbox = (CheckBox)textEntryView2.findViewById(R.id.checkBox1);
		    final Spinner spinner2 = (Spinner)textEntryView2.findViewById(R.id.setting_spinner2);
			List<String> list = new ArrayList<String>();
			list.add("1");
			list.add("5");
			list.add("10");
			list.add("15");
			list.add("30");
			ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mContext,
				android.R.layout.simple_spinner_item, list);
			dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			spinner2.setAdapter(dataAdapter);
			spinner2.setSelection(mNotifTimerSelection);
		    spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
	
				@Override
				public void onItemSelected(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					mNotifTimer = Integer.parseInt(arg0.getItemAtPosition(arg2).toString());
					mNotifTimerSelection = arg2;
				}
				@Override
				public void onNothingSelected(AdapterView<?> arg0) {
					// TODO Auto-generated method stub
					
				}
			});
		    
		    if(mNotifEnable) checkbox.setChecked(true);
		    else 	checkbox.setChecked(false);
		    if(checkbox.isChecked()) mNotifEnable = true;
		    else mNotifEnable = false;
		    Builder alert2 = new AlertDialog.Builder(mContext);
		    alert2.setView(textEntryView2);
		    alert2.setTitle("Setting");
		    alert2.show();
	        return true;
//      case R.id.menu_favourite:
//			Intent i = new Intent(mContext,pageUserCP.class );
//			startActivity(i);
//			return true;
      case R.id.menu_font:
    	  	setFont();
	          return true;
      	default:
          return super.onOptionsItemSelected(item);
      }
  }
  public void setFont(){
	  LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    View layout = inflater.inflate(R.layout.seekbar, null);
	    AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(layout);
	    AlertDialog alertDialog = builder.create();
	    alertDialog.show();
	    SeekBar sb = (SeekBar)layout.findViewById(R.id.seek);
	    sb.setMax(30);
	    sb.setProgress((int)(30*(Voz.mTextSize-Voz.FONTSCALE_MIN)/(Voz.FONTSCALE_MAX-Voz.FONTSCALE_MIN)));
	    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
	        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
	        	Voz.mTextSize = (float)((Voz.FONTSCALE_MAX-Voz.FONTSCALE_MIN)/(30-0)*(progress) + Voz.FONTSCALE_MIN);
	        	//adapter.setSize(Voz.mTextSize);
	        	//adapter.notifyDataSetChanged();
	        }
				@Override
				public void onStartTrackingTouch(SeekBar arg0) {
					// TODO Auto-generated method stub

				}
				@Override
				public void onStopTrackingTouch(SeekBar arg0) {
					// TODO Auto-generated method stub
				}
	    });
  }

}
